#!/usr/bin/env bash
set -e

ROOT=$PWD
BUILD_ARM=$ROOT/build/ios-arm64
BUILD_X64=$ROOT/build/ios-x64
OUT=$ROOT/build/ios-universal

# 1. 真机
cmake -B $BUILD_ARM \
  -DCMAKE_TOOLCHAIN_FILE=$ROOT/ios-toolchain.cmake \
  -DCMAKE_OSX_ARCHITECTURES=arm64 \
  -DCMAKE_BUILD_TYPE=MinSizeRel
cmake --build $BUILD_ARM

# 2. 模拟器
cmake -B $BUILD_X64 \
  -DCMAKE_TOOLCHAIN_FILE=$ROOT/ios-toolchain.cmake \
  -DCMAKE_OSX_ARCHITECTURES=x86_64 \
  -DCMAKE_BUILD_TYPE=MinSizeRel
cmake --build $BUILD_X64

# 3. 合并
mkdir -p $OUT
lipo -create \
  $BUILD_ARM/libspeex_jni.a \
  $BUILD_X64/libspeex_jni.a \
  -output $OUT/libspeex_jni.a

cp $ROOT/speex_jni.h $OUT/